#include "stdafx.h"
#include "PPContextImp.h"
#include "utilityString.h"
#include "LBProjPlanStream\LBProjPlanDataBase.h"
#include "PPContextReadWriteHelper.h"

namespace LBPROJ
{
    CPPContext::CPPContext()
    {
        m_pCalendar = new CCalendar();
        m_pTaskGroup = new CTaskGroup(this);
    }

    CPPContext::~CPPContext()
    {
    }

    void CPPContext::SetID(const std::wstring& id) const
    {
        m_id = id;
    }

    const std::wstring& CPPContext::GetID() const
    {
        if (m_id.empty())
        {
            m_id = GenerateUUID();
        }
        return m_id;
    }

    CRefPtr<ITaskGroup> CPPContext::GetTaskGroup()
    {
        return m_pTaskGroup;
    }

    CRefPtr<ICalendar> CPPContext::GetCalendar() const
    {
        return m_pCalendar;
    }

    bool CPPContext::Open(LBPROJSTREAM::IProjPlanStreamDatabase* pDb)
    {
        CPPContextReadWriteHelper helper(this);
        return helper.Open(pDb);
    }

    bool CPPContext::Write(LBPROJSTREAM::IProjPlanStreamDatabase* pDb) const
    {
        CPPContextReadWriteHelper helper((CPPContext*)this);
        return helper.Write(pDb);
    }

    CRefPtr<IPPContext> CreateContext()
    {
        return new CPPContext();
    }
}
